// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_PUR_QUOTATION
// * CreateDate    : 2014-02-18 18:04:11
// * Creater       : CodeSmith
// * LastChangeDate: 2014-02-18 18:04:11
// * LastChanger   : 2014-02-18 18:04:11
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Pur
{
/// <summary>
    /// PurQuotation
    /// </summary>
    public partial class PurQuotationBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objPurQuotationEntity">Entity</param>
        /// <returns>Entity</returns>
        public static PurQuotationEntity GetPurQuotation(PurQuotationEntity objPurQuotationEntity)
        {
            return DataAccess.SelectSingle<PurQuotationEntity>(objPurQuotationEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objPurQuotationEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertPurQuotation(PurQuotationEntity objPurQuotationEntity)
        {
            return DataAccess.Insert(objPurQuotationEntity);
        }

        public static bool InsertPurQuotation(List<PurQuotationEntity> objPurQuotationEntityList)
        {
            return DataAccess.Insert(objPurQuotationEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objPurQuotationEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdatePurQuotation(PurQuotationEntity objPurQuotationEntity)
        {
            return DataAccess.Update(objPurQuotationEntity);
        }

        public static bool UpdatePurQuotation(List<PurQuotationEntity> objPurQuotationEntityList)
        {
            return DataAccess.Update<PurQuotationEntity>(objPurQuotationEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objPurQuotationEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeletePurQuotation(PurQuotationEntity objPurQuotationEntity)
        {
            return DataAccess.Delete(objPurQuotationEntity);
        }

        public static bool DeletePurQuotation(List<PurQuotationEntity> objPurQuotationEntityList)
        {
            return DataAccess.Delete<PurQuotationEntity>(objPurQuotationEntityList);
        }

        public static bool DeletePurQuotation(PurQuotationEntity objPurQuotationEntity,List<PurQuotationItemEntity> items)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    if (items != null)
                        DataAccess.Delete(items, broker);
                    DataAccess.Delete(objPurQuotationEntity, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    return false;
                }
            }
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetPurQuotationAll()
        {
            return DataAccess.SelectAllDataSet<PurQuotationEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<PurQuotationEntity> GetPurQuotationAllList()
        {
            return DataAccess.SelectAll<PurQuotationEntity>();
        }
        #endregion

        public static bool AddPurQu(PurQuotationEntity qu, List<PurQuotationItemEntity> items)
        {
            if (qu == null)
                return false;
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Insert(qu, broker);
                    if (items != null)
                        DataAccess.Insert(items, broker);

                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    return false;
                }
            }

        }

        public static bool UpdatePurQu(PurQuotationEntity qu, List<PurQuotationItemEntity> addItems, List<PurQuotationItemEntity> updateItems)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Update(qu, broker);
                    if (addItems != null)
                    {
                        DataAccess.Insert(addItems, broker);
                    }
                    if (updateItems != null)
                    {
                        DataAccess.Update(updateItems, broker);
                    }
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    return false;
                }
            }
        }

	}
	
	
}	

